//
//  AppDelegate.m
//  YSZC
//
//  Created by 张斌 on 16/4/11.
//  Copyright © 2016年 YueShiKeJi. All rights reserved.
//appkey
// 友盟：57296dcae0f55a163700001a

#import "AppDelegate.h"

#import "BINcollectionviewcontroller.h"

#import "YSMainTabBarViewController.h"

#import "YSLoginViewController.h"

#import "LoadVcManager.h"
#import "UMSocial.h"
#import "UMSocialWechatHandler.h"
#import "UMSocialSinaSSOHandler.h"
#import "UMSocialQQHandler.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      [UMSocialData setAppKey:@"57296dcae0f55a163700001a"];
    
    [UMSocialSinaSSOHandler openNewSinaSSOWithAppKey:@"3634751622" secret: @"ccef3775d83e5059bedb482c37ef5661"RedirectURL:@"http://www.yuevision.com" ];
    
    [UMSocialQQHandler setQQWithAppId:@"1105303763" appKey:@"fMX9XCP3dtFw72RN" url:@"http://baidu.com"];
    
    [UMSocialWechatHandler setWXAppId:@"wxd82db355ede95af4" appSecret:@"b95c03e85c3cbf959b759ba23b51742c" url:@"http://www.yuevision.com"];
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    // 最终的
// [self beganselectrootview];
    // 代码的
//    self.window.rootViewController = [self testVCWithClassname:@"YSMainTabBarViewController"];
    // sb的
    self.window.rootViewController = [LoadVcManager sbVCWithsbname:@"YSLoginViewController"];
    
    
    [self.window makeKeyAndVisible];
    
    return YES;
}

// 测试选择控制器的方法
-(UIViewController*)testVCWithClassname:(NSString*)classname{

    UIViewController* VC = [[NSClassFromString(classname) alloc] init];
    
    return VC;
}

- (void)beganselectrootview{
    // 获取当前的版本号
    NSString* currentverson=[NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
    
    // 从偏好设置中取出存储的版本号
    NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
    
    NSString* saveverson=[defaults objectForKey:@"verson"];
    
    if (![currentverson isEqualToString:saveverson]) {
        
        
//        YSMainTabBarViewController* tabbarVC=[[YSMainTabBarViewController alloc] init];
        
        
//        self.window.rootViewController=tabbarVC;
//        YSLoginViewController* loginvc = [[YSLoginViewController alloc] init];
//        self.window.rootViewController = loginvc;
        
        self.window.rootViewController= [LoadVcManager sbVCWithsbname:@"YSLoginViewController"];
        
        
    }else{
        
        BINcollectionviewcontroller* collectioncontroller=[[BINcollectionviewcontroller alloc] init];
        
        self.window.rootViewController=collectioncontroller;
        
        [defaults setObject:currentverson forKey:@"verson"];
    }
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
